﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pattern_package.Create_Correct_Pattern;

namespace Pattern_package.Classify_data
{
   public class Baysian
    {
        //public double[] probOfXGivenC;
        private double calcGiven(double[] probOfXGivenClassI, double x,int IndexOfNeedClass)
        {
            double probOfEachClass = 1.0 / probOfXGivenClassI.Length;
            double ProbalbilityOfX=0;
            for (int i = 0; i < probOfXGivenClassI.Length; i++)
            {
                ProbalbilityOfX += probOfXGivenClassI[i];
            }

                return probOfXGivenClassI[IndexOfNeedClass] / ProbalbilityOfX;
        }
        public int ChooseType(NormalDistrubution[] ClassiesInfo, double x)
        {
                        Normal_dis class1 = new Normal_dis();
                        double[] probOfXGivenClassI = new double[ClassiesInfo.Length];
             double[] probOfClassIGivenX=new double[ClassiesInfo.Length];
                        for (int i = 0; i < ClassiesInfo.Length; i++)
                        {
                             probOfXGivenClassI[i] = class1.CalcNormalTODefineX(x, ClassiesInfo[i].mean, ClassiesInfo[i].sigma);
                        }
                        for (int i = 0; i < ClassiesInfo.Length; i++)
                        {
                            probOfClassIGivenX[i] = calcGiven(probOfXGivenClassI, x,i);
                        }
                        int index = 0;
            double max=probOfClassIGivenX[0];
            for (int i = 1; i < ClassiesInfo.Length; i++)
            {
                if (probOfClassIGivenX[i] == max)
                {
                    index = -1;
                }
                else if (probOfClassIGivenX[i] > max)
                {
                    index = i;
                    max = probOfClassIGivenX[i];

                }
            }
                        return index;
        }

    }
}
